//
//  AppTvCaseCCell.m
//  classicFilms
//
//  Created by 刘继丹 on 17/4/24.
//  Copyright © 2017年 Stefan Arn. All rights reserved.
//

#import "AppTvCaseCCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
#import "KeyHeader.h"

@interface AppTvCaseCCell()

@property(nonatomic, strong) UIImageView *mImageView, *mMarkImageView;
@property(nonatomic, strong) UIView *mBackView;
@property(nonatomic, strong) UILabel *mTitleLabel, *mSubtitleLabel;

@end

@implementation AppTvCaseCCell

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.mImageView];
        [self.contentView addSubview:self.mBackView];
        [self.mBackView addSubview:self.mMarkImageView];
        [self.mBackView addSubview:self.mTitleLabel];
        [self.mBackView addSubview:self.mSubtitleLabel];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    _mImageView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    _mBackView.frame = CGRectMake(_mImageView.frame.size.width/2.f-180, _mImageView.frame.size.height/2.f-80, 360, 160);
    UIImage *image = [UIImage imageNamed:@"case_mark"];
    _mMarkImageView.frame = CGRectMake(_mBackView.frame.size.width/2.f-image.size.width/2.f, 20, image.size.width, image.size.height);
    _mTitleLabel.frame = CGRectMake(0, _mMarkImageView.frame.origin.y+image.size.height+28, _mBackView.frame.size.width, 36);
    _mSubtitleLabel.frame = CGRectMake(0, _mTitleLabel.frame.origin.y+_mTitleLabel.frame.size.height+26, _mTitleLabel.frame.size.width, 22);
}

-(void)setDic:(NSDictionary *)dic{
    if (_dic != dic) {
        _dic = dic;
    }
    
    NSString *title = [_dic objectForKey:@"title"];
    NSString *subtitle = [_dic objectForKey:@"sub_title"];

    NSString *imageName = [_dic objectForKey:@"cover_url"];
    [_mImageView sd_setImageWithURL:[NSURL URLWithString:imageName]];
    _mMarkImageView.image = [UIImage imageNamed:@"case_mark"];
    _mTitleLabel.text = title;
    _mSubtitleLabel.text = subtitle;
}

-(UIImageView *)mImageView{
    if (!_mImageView) {
        _mImageView = [[UIImageView alloc]init];
        _mImageView.adjustsImageWhenAncestorFocused = YES;
        _mImageView.contentMode = UIViewContentModeScaleToFill;
    }
    return _mImageView;
}

-(UIImageView *)mMarkImageView{
    if (!_mMarkImageView) {
        _mMarkImageView = [[UIImageView alloc]init];
    }
    return _mMarkImageView;
}

-(UIView *)mBackView{
    if (!_mBackView) {
        _mBackView = [[UIView alloc]init];
        _mBackView.backgroundColor =  [[UIColor blackColor] colorWithAlphaComponent:0.45];
    }
    return _mBackView;
}

-(UILabel *)mTitleLabel{
    if (!_mTitleLabel) {
        _mTitleLabel = [[UILabel alloc]init];
        _mTitleLabel.textColor = [UIColor whiteColor];
        _mTitleLabel.font = [UIFont boldSystemFontOfSize:36];
        _mTitleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _mTitleLabel;
}

-(UILabel *)mSubtitleLabel{
    if (!_mSubtitleLabel) {
        _mSubtitleLabel = [[UILabel alloc]init];
        _mSubtitleLabel.textColor = [UIColor whiteColor];
        _mSubtitleLabel.font = [UIFont boldSystemFontOfSize:20];
        _mSubtitleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _mSubtitleLabel;
}


@end
